<template>
	<view style="padding-top: 60px;" class="building">
		<view class="inputArea u-p-b-50" style="text-align: center;">
			<image class="logo-img" src="https://account-book-cos.1900shop.online/static/images/login/money.png"></image>
		</view>
		<view class="u-text-center  u-p-b-50">
			<text class="u-font-18 u-main-color">币迹</text>
		</view>
		<view class="u-text-center u-p-b-50">
			<text class="u-font-13 u-main-color">家常记账，知悭识俭</text>
		</view>
		<view class="inputArea">
			<button class="login-button" @click="goLogin">翻开记账簿</button>
		</view>
	</view>
</template>

<script>
	let _this;
	export default {
		data() {
			return {
				phoneModalShow: false,
				hasLogin: false,
				option: ''
			}
		},
		onLoad(e) {
			uni.hideHomeButton();
			_this = this;
			console.log("登录页：" + JSON.stringify(e))
			if (e) {
				_this.option = e
			}
		},
		methods: {
			//登录
			goLogin() {
				uni.showLoading({
					title: '正在授权登录中........'
				});
				uni.getUserProfile({
					desc: '登录',
					success: (infoRes) => {
						//这里取到的是用户的信息，自己安排自己的业务
						uni.login({
							provider: 'weixin',
							success: (loginRes) => {
								//发生请求
								_this.$u.api.login({
									code: loginRes.code,
									rawData: infoRes.rawData,
									signature: infoRes.signature,
									encryptedData: infoRes.encryptedData,
									iv: infoRes.iv
								}).then(res => {
									if (res) {
										_this.$u.toast('登陆成功')
										_this.$u.vuex('os_token', res.token);
										_this.$u.vuex('os_user', res);
										_this.goTabbarUrl('/pages/app/index')
									}
								})
							}
						})
					},
					fail: (err) => {
						uni.hideLoading();
						uni.showToast({
							icon: "none",
							title: '翻开记数簿要允许授权'
						});
					}
				})
			},
			//跳转到页面关闭其他页面
			goTabbarUrl(path) {
				if (_this.option) {
					path = path + "?" + _this.option
				}
				console.log("登录后跳转地址：" + path)
				uni.reLaunch({
					url: path
				});
			},
		}
	}
</script>

<style>
	.inputArea {
		padding: 50upx 10%;
	}

	.logo-img {
		width: 100upx;
		height: 100upx;
		border-radius: 150upx;
	}

	.login-button {
		color: #FFFFFF;
		background-color: #ff0000;
		border-radius: 60upx;
		font-size: 30upx;
		text-align: center;
		padding: 3upx;
		width: 60%;
	}

	.building {
		opacity: 0.75;
		background: url("https://account-book-cos.1900shop.online/static/images/login/background.png");
		width: 100%;
		height: 100%;
		position: fixed;
		background-size: 100% 100%;
	}
</style>